package com.lz.base.common.utils.common;

import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;

/**
 * @Author yunnuo.yang
 * @Date 2021/2/9 11:55
 * @Description
 **/
public class DateLogUtil {
    private static final String timePattern="yyyy-MM-dd hh:mm:ss";
    private static final String datePattern="yyyy-MM-dd";

    /**
     *
     * @param localDateTime
     * @return 格式化时间
     */
    public static String formatTime(LocalDateTime localDateTime) {
        DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern(timePattern);
        String format = dateTimeFormatter.format(localDateTime);
        return format;
    }

    /**
     *
     * @param millis
     * @return 时间戳转时间
     */
    public static LocalDateTime millisToDate(long millis) {
        LocalDateTime localDateTime = LocalDateTime.ofInstant(Instant.ofEpochMilli(millis), ZoneId.systemDefault());
        return localDateTime;
    }

    /**
     *
     * @param dateStr
     * @return 时间戳转时间
     */
    public static LocalDate stringToDate(String dateStr) {
        DateTimeFormatter  fomatter=DateTimeFormatter.ofPattern(datePattern);
        //执行解析
        LocalDate dtl=LocalDate.parse(dateStr,fomatter);
        return dtl;
    }
}
